﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.SessionState;
using DevCore.Entity.System;
using DevCore.Service.Permission;
using DevCore.Web;
using DevCore.Web.Base;

namespace DevFrameWork.Web.AppService.Login
{
    public class LoginHandler :  IHttpHandler, IRequiresSessionState
    {
        /// <summary>
        /// 处理用户请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            String retValue = "";
            String strCmd = RequestHelper.GetQueryString("cmd");
            strCmd = strCmd.ToLower();
            if(strCmd.Equals("docheck"))
            {
                retValue = LoginCheck();
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write(retValue);

        }

        /// <summary>
        /// 检查用户名与密码的登录
        /// </summary>
        public String LoginCheck()
        {
            String rValue = String.Empty;

            String sUserName = RequestHelper.GetFormString("edtUserName");
            String sUserPassword = RequestHelper.GetFormString("edtUserPassword");
            String sOrgCode = RequestHelper.GetFormString("edtOrgCode");
            UserLoginInfo curUserLoginInfo = new UserLoginInfo();
            int status = UserInfoService.CheckUserLogin(sUserName, sUserPassword, sOrgCode, out curUserLoginInfo);
            rValue = status.ToString();
            return rValue;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
